unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus,ComObj,ComCtrls,FUtils,FRunEnvt;

type
  TFormMain = class(TForm)
    MainMenu1: TMainMenu;
    est11: TMenuItem;
    est12: TMenuItem;
    procedure est12Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure DoShowOleForm(AProgID,AParam: String;AFormShowType : Integer);
  protected
    procedure WmOleFormCommand(var Message: TMessage); message WM_OLEFORMCOMMAND;
  public
    { Public declarations }
  end;

var
  FormMain: TFormMain;

implementation
uses Test1;

{$R *.dfm}

procedure TFormMain.DoShowOleForm(AProgID,AParam: String;AFormShowType : Integer);
var
  bExists: Boolean;
  oOleForm: TMDIOleControlForm;
begin
  bExists := False;
  if AProgID <> '' then
  begin
    RegisterComClass(AProgID, rctDll);
    ComClassCheck(AProgID, rctDll);
    bExists := True;
    if bExists then
    begin
      oOleForm := TMDIOleControlForm.Create(ProgIDToClassID(AProgID), AParam);
      Try
        if oOleForm.InstanceAllocated then
        begin
          oOleForm.ShowOleForm(TFormShowType(AFormShowType));
        end
        else begin
          oOleForm.CloseOleForm;
        end;
      Finally
        oOleForm.Free;
      End;
    end;

  end;
end;

procedure TFormMain.est12Click(Sender: TObject);
begin
//  application.CreateForm(TFormTest1,FormTest1);
  DoShowOleForm('AnyiHisBLEdit2011.AnyiHis_BLEdit','',0);
end;

procedure TFormMain.WmOleFormCommand(var Message: TMessage);
begin
  With Message Do
  begin
    Result := 0;

    ShowMessage('aa');
    
  end;
end;

procedure TFormMain.FormCreate(Sender: TObject);
begin
  GV_MainHandle := Self.Handle;
end;

end.
